/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package x2rel.qMap.core;

import x2rel.qMap.logger.Logging;

/**
 *
 * @author Leonardo Nicorena <lnicorena at inf.ufsm.br>
 */
public class Equivalencias extends Utils {

    private Integer cod;
    private String tipo;
    private String xmlResult;
    /*
    <relational>
    <column>{$c/relational/name/text()}</column>
    <table>{$c/relational/table/text()}</table>
    <domain>{$c/relational/domain/text()}</domain>
    </relational>
     */

    public Equivalencias(String tipo, String result, Integer cod) {
        this.tipo = tipo;
        this.xmlResult = result;
        this.cod = cod;
    }

    public String getColumn() {
        String xq = //" xquery version \"1.0\";" +
                " for $c in /relational/column"
                + " return $c/text()";
        String s = runXquery(this.xmlResult, xq);
        //Logging.getInstance().log( String.valueOf(s.length()), 3);
        if (s.length() > 38) {
            return (String) s.subSequence(38, s.length());
        } else {
            return "";
        }
    }

    public String getTable() {
        String xq = //" xquery version \"1.0\";" +
                " for $c in /relational/table"
                + " return $c/text()";

        String s = runXquery(this.xmlResult, xq);
        if (s.length() > 38) {
            return (String) s.subSequence(38, s.length());
        } else {
            return "";
        }
    }

    public String getDomain() {
        String xq = //" xquery version \"1.0\";" +
                " for $c in /relational/domain"
                + " return $c/text()";

        String s = runXquery(this.xmlResult, xq);
        if (s.length() > 38) {
            return (String) s.subSequence(38, s.length());
        } else {
            return "";
        }
    }
    
    public String getType() {
        String xq = //" xquery version \"1.0\";" +
                " for $c in /relational/type"
                + " return $c/text()";

        String s = runXquery(this.xmlResult, xq);
        if (s.length() > 38) {
            return (String) s.subSequence(38, s.length());
        } else {
            return "";
        }
    }
    
    public String getName() {
        String xq = //" xquery version \"1.0\";" +
                " for $c in /relational/name"
                + " return $c/text()";

        String s = runXquery(this.xmlResult, xq);
//        Logging.getInstance().log( "HÁ!!!!!\n" + this.xmlResult , 3);
//        Logging.getInstance().log( "HÁ!!!!!\n" + (String) s.subSequence(38, s.length()) , 3);
        if (s.length() > 38) {
            return (String) s.subSequence(38, s.length());
        } else {
            return "";
        }
    }

    public String getTipo() {
        return tipo;
    }

    public void setTipo(String tipo) {
        this.tipo = tipo;
    }

    public String getXmlResult() {
        return xmlResult;
    }

    public void setXmlResult(String xmlResult) {
        this.xmlResult = xmlResult;
    }

    public Integer getCod() {
        return cod;
    }

    public void setCod(Integer cod) {
        this.cod = cod;
    }
}
